package categoryModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import modules.Wikimap;
import parameter.*;
import functions.FileFunction;
import functions.TermFunction;

public class GenNaverWikiSubCategoryModel {
	
	public static void main(String args[]) throws Exception{
		
		String sourcePath = Path.CATEGORY_MODEL_WIKI_CFICF_PATH;
		Wikimap wikimap = new Wikimap();
		
		for (int i = 1; i <= 10; i++) {
			Exp.subCategoryWeight_Naver = 0.1 * i;
			System.out.println(i);
			
			String targetPath = Path.CATEGORY_MODEL_WIKI_CFICF_SUB_PATH + String.format("%.1f", Exp.subCategoryWeight_Naver) + "\\";

			Map<String, Map<String,Double>> map = FileFunction.readMapStr_StrDou(sourcePath);
			Map<String, Map<String,Double>> map2 = new HashMap<String, Map<String, Double>>();
			
			for (Entry<String, Map<String, Double>> entry : map.entrySet()) {
				String key = entry.getKey();
				//System.out.println("Loading "+key);				
				Map<String, Double> value = entry.getValue();
				//-------------------------------  MODIFICATION PROCESS  ----------------------------------//

				Map<String, Double> totalCategoryMap = new HashMap<String, Double>();
				Map<String, Double> categoryMap = TermFunction.getNorm(value);
				Map<String, Double> subCategoryMap = new HashMap<String, Double>();

				for (Entry<String, Double> entry2 : categoryMap.entrySet()) {
					String key2 = entry2.getKey();
					Double value2 = entry2.getValue();
					List<String> subCategoryList = wikimap.getSubCategory(key2);
					for(String subCategory : subCategoryList){
						subCategoryMap.put(subCategory, value2);
					}
				}
				subCategoryMap = TermFunction.getNorm(subCategoryMap);
				totalCategoryMap = TermFunction.CombineCountsWeight(categoryMap, subCategoryMap, 1.0 - Exp.subCategoryWeight_Naver, Exp.subCategoryWeight_Naver);

				map2.put(key, TermFunction.getNorm(totalCategoryMap));
				//-----------------------------------------------------------------------------------------//
			}
			FileFunction.writeMapStr_StrDou(map2, targetPath);

		}
		
		System.out.println("complete");

	}
	
	
	
}
